#include <iostream>
#include <unordered_map>
#include <cmath>

bool isPrime(int number) {
    if (number < 2)
        return false;
    for (int i = 2; i <= sqrt(number); ++i) {
        if (number % i == 0)
            return false;
    }
    return true;
}

int main() {
    std::unordered_map<std::string, int> wordToNumber = {
        {"zero", 0},
        {"one", 1},
        {"two", 2},
        {"three", 3},
        {"four", 4},
        {"five", 5},
        {"six", 6},
        {"seven", 7},
        {"eight", 8},
        {"nine", 9}
    };

    std::string input;
    std::getline(std::cin, input);

    size_t pos1 = input.find(' ');
    size_t pos2 = input.find(' ', pos1 + 1);
    
    if (pos1 == std::string::npos || pos2 == std::string::npos) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }

    std::string word1 = input.substr(0, pos1);
    std::string word2 = input.substr(pos1 + 1, pos2 - pos1 - 1);
    std::string word3 = input.substr(pos2 + 1);

    if (wordToNumber.find(word1) == wordToNumber.end() ||
            wordToNumber.find(word2) == wordToNumber.end() ||
            wordToNumber.find(word3) == wordToNumber.end()) {
        std::cout << "Wrong input" << std::endl;
                return 0;
            }
    
            int number = wordToNumber[word1] * 100 + wordToNumber[word2] *10 + wordToNumber[word3];
    
            int lowerPrime = number;
    
            while (!isPrime(lowerPrime)) {
                lowerPrime--;
            }
    
            int upperPrime = number;
    
            while (!isPrime(upperPrime)) {
                upperPrime++;
            }
    
            std::cout << lowerPrime << std::endl;

return 0; 
}